import {param2Obj} from '@/utils'

const dailyDetail = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 50 + 30); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      mp_name: '公众号' + i,
      cost: (Math.random() * 8000 + 3000).toFixed(2),
      earning: (Math.random() * 8000 + 3000).toFixed(2),
      fans_count: Math.floor((Math.random() * 500 + 200)),
      new_fans: Math.floor((Math.random() * 300 + 100)),
      lost_fans: Math.floor((Math.random() * 100 + 50)),
      net_increase_fans: Math.floor((Math.random() * 100 + 50)),
      operater: Math.floor(Math.random() * 2) ? '张三' : '李四',
      use_system: Math.floor(Math.random() * 2) ? '系统一' : '系统二',
      launch_channel: Math.floor(Math.random() * 2) ? '渠道一' : '渠道二',
      launch_corp: Math.floor(Math.random() * 2) ? '公司一' : '公司二',
      per_fan_cost: (Math.random() * 100 + 50).toFixed(2),
      per_fan_earning: (Math.random() * 100 + 50).toFixed(2)
    })
  }
  return arr
})()
const sales_volume = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 50 + 30); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      name: '人员' + i,
      bm_name: (Math.random() * 8000 + 3000).toFixed(2),
      income: (Math.random() * 8000 + 3000).toFixed(2),
      act_income: (Math.random() * 500 + 200).toFixed(2),
      total_cost: (Math.random() * 300 + 100).toFixed(2),
      act_rate: (Math.random() * 100).toFixed(2) + '%',
      total_fans: Math.floor((Math.random() * 100 + 50)),
      increase_fans: Math.floor(Math.random() * 100 + 50)
    })
  }
  return arr
})()
const tencentData = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 50 + 30); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      mp_name: '公众号' + i,
      total_fans: (Math.random() * 8000 + 3000).toFixed(2),
      total_cost: (Math.random() * 8000 + 3000).toFixed(2),
      income: Math.floor((Math.random() * 500 + 200)),
      act_income: Math.floor((Math.random() * 300 + 100)),
      recovery_rate: Math.floor((Math.random() * 100 + 50)),
      daily_income: Math.floor((Math.random() * 100 + 50)),
      payback_period: Math.floor((Math.random() * 100 + 50)),
      remaining_time: Math.floor((Math.random() * 100 + 50)),
      use_system: Math.floor(Math.random() * 2) ? '负责人一' : '负责人二',
      operater: Math.floor(Math.random() * 2) ? '系统一' : '系统二',
      launch_channel: Math.floor(Math.random() * 2) ? '渠道一' : '渠道二',
      launch_corp: Math.floor(Math.random() * 2) ? '公司一' : '公司二',
      per_fan_cost: (Math.random() * 100 + 50).toFixed(2),
      per_fan_earning: (Math.random() * 100 + 50).toFixed(2)
    })
  }
  return arr
})()
const tencentDetail = {
  total_fans: (Math.random() * 8000 + 3000).toFixed(2),
  total_cost: (Math.random() * 8000 + 3000).toFixed(2),
  income: Math.floor((Math.random() * 500 + 200)),
  act_income: Math.floor((Math.random() * 300 + 100)),
  recovery_rate: Math.floor((Math.random() * 100 + 50)),
  daily_income: Math.floor((Math.random() * 100 + 50)),
  payback_period: Math.floor((Math.random() * 100 + 50)),
  remaining_time: Math.floor((Math.random() * 100 + 50)),
  use_system: Math.floor(Math.random() * 2) ? '负责人一' : '负责人二',
  owner_corp: Math.floor(Math.random() * 2) ? '主体一' : '主体二',
  operater: Math.floor(Math.random() * 2) ? '系统一' : '系统二',
  launch_channel: Math.floor(Math.random() * 2) ? '渠道一' : '渠道二',
  launch_corp: Math.floor(Math.random() * 2) ? '公司一' : '公司二',
  per_fan_cost: (Math.random() * 100 + 50).toFixed(2),
  per_fan_earning: (Math.random() * 100 + 50).toFixed(2),
  launch_state: Math.round(Math.random()),
  launch_date: '2019-01-01',
  per_fan_income: Math.floor((Math.random() * 100 + 50))
}
const company = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 50 + 30); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      corp_name: '公司' + i,
      total_recharge: (Math.random() * 8000 + 3000).toFixed(2),
      total_cost: (Math.random() * 8000 + 3000).toFixed(2),
      total_balance: Math.floor((Math.random() * 500 + 200)),
      income: Math.floor((Math.random() * 300 + 100)),
      act_rate: Math.floor((Math.random() * 100 + 50)),
      act_income: Math.floor((Math.random() * 100 + 50)),
      recovery_rate: Math.floor((Math.random() * 100 + 50)),
      daily_income: Math.floor((Math.random() * 100 + 50)),
      remaining_time: Math.floor(Math.random() * 2) ? '负责人一' : '负责人二'
    })
  }
  return arr
})()
const companyFormDetail = {
  corp_name: (Math.random() * 8000 + 3000).toFixed(2),
  total_recharge: (Math.random() * 8000 + 3000).toFixed(2),
  total_cost: Math.floor((Math.random() * 500 + 200)),
  total_balance: Math.floor((Math.random() * 300 + 100)),
  income: Math.floor((Math.random() * 100 + 50)),
  act_rate: Math.floor((Math.random() * 100 + 50)),
  act_income: Math.floor((Math.random() * 100 + 50)),
  recovery_rate: Math.floor((Math.random() * 100 + 50)),
  daily_income: Math.floor(Math.random() * 2) ? '负责人一' : '负责人二',
  remaining_time: Math.floor(Math.random() * 2) ? '系统一' : '系统二'
}
const companyChargeList = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 4); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      pay_corp: '公司' + i,
      money: (Math.random() * 8000 + 3000).toFixed(2)
    })
  }
  return arr
})()
const channel = (() => {
  const arr = []
  for (let i = 1, len = (Math.random() * 50 + 30); i < len; i++) {
    arr.push({
      id: i,
      date: '2019-01-' + i,
      chnl_name: '渠道' + i,
      total_cost: (Math.random() * 8000 + 3000).toFixed(2),
      income: (Math.random() * 8000 + 3000).toFixed(2),
      act_rate: Math.floor((Math.random() * 500 + 200)),
      act_income: Math.floor((Math.random() * 300 + 100)),
      recovery_rate: Math.floor((Math.random() * 100 + 50)),
      daily_income: Math.floor((Math.random() * 100 + 50)),
      remaining_time: Math.floor((Math.random() * 100 + 50)),
      corp_name: Math.floor((Math.random() * 100 + 50))
    })
  }
  return arr
})()
const arr_corp_perf = (() => {
  return [
    {
      name: '微赞',
      money: 3434,
      total_cost: '3453',
      income: '3453',
      act_income: '3453',
      total_fans: '3453',
      payback_period: '3453',
      remaining_time: '3453',
      daily_income: '3453',
      per_fan_cost: '3453'
    },
    {
      name: '乾丰',
      money: 3434,
      total_cost: '3453',
      income: '3453',
      act_income: '3453',
      total_fans: '3453',
      payback_period: '3453',
      remaining_time: '3453',
      daily_income: '3453',
      per_fan_cost: '3453'
    }
  ]
})()
const arr_cycle_perf = (() => {
  return [
    {
      name: '总',
      total_cost: 23434,
      income: 23434,
      // act_income: 23434,
      total_fans: 23434,
      net_increase_fans: 3434
    },
    {
      name: '月',
      total_cost: 23434,
      income: 23434,
      act_income: 23434,
      // total_fans: '23434',
      net_increase_fans: 3434
    },
    {
      name: '周',
      total_cost: 23434,
      income: 23434,
      act_income: 23434,
      // total_fans: '23434',
      net_increase_fans: 3434
    },
    {
      name: '日',
      total_cost: 23434,
      income: 23434,
      act_income: 23434,
      // total_fans: '23434',
      net_increase_fans: 3434
    }
  ]
})()
export default {
  getDailyList: config => {
    const body = param2Obj(config.url)
    const startIndex = ((+body.page || 1) - 1) * (+body.rows || 30)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        list: dailyDetail.slice(startIndex, +startIndex + (+body.rows || 30)),
        pageNumber: body.page || 1,
        pageSize: body.rows || 30,
        totalPage: Math.ceil(dailyDetail.length / (body.rows || 30)),
        totalRow: dailyDetail.length
      }
    }
  },
  // 修改每日明细
  modifyDailyDetail: config => {
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: ''
    }
  },
  // 员工业绩列表
  getSalesVolumeList: config => {
    const body = param2Obj(config.url)
    const startIndex = ((+body.page || 1) - 1) * (+body.rows || 30)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        list: sales_volume.slice(startIndex, +startIndex + (+body.rows || 30)),
        pageNumber: body.page || 1,
        pageSize: body.rows || 30,
        totalPage: Math.ceil(dailyDetail.length / (body.rows || 30)),
        totalRow: dailyDetail.length
      }
    }
  },
  // 公众号数据列表
  getTencentList: config => {
    const body = param2Obj(config.url)
    const startIndex = ((+body.page || 1) - 1) * (+body.rows || 30)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        list: tencentData.slice(startIndex, +startIndex + (+body.rows || 30)),
        pageNumber: body.page || 1,
        pageSize: body.rows || 30,
        totalPage: Math.ceil(dailyDetail.length / (body.rows || 30)),
        totalRow: dailyDetail.length
      }
    }
  },
  // 公众号详情
  getTencentDetail: config => {
    const body = param2Obj(config.url)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {...tencentDetail, id: body.id, mp_name: '公众号' + body.id}
    }
  },
  // 投放公司列表
  getCompanyList: config => {
    const body = param2Obj(config.url)
    const startIndex = ((+body.page || 1) - 1) * (+body.rows || 30)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        list: company.slice(startIndex, +startIndex + (+body.rows || 30)),
        pageNumber: body.page || 1,
        pageSize: body.rows || 30,
        totalPage: Math.ceil(dailyDetail.length / (body.rows || 30)),
        totalRow: dailyDetail.length
      }
    }
  },
  // 公司详情
  getCompanyDetail: config => {
    const body = param2Obj(config.url)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        details: {...companyFormDetail, id: body.id, mp_name: '公众号' + body.id},
        chargeList: companyChargeList,
        tencentList: tencentData.slice(0, Math.random() * 15 + 5)
      }
    }
  },
  // 新增公司
  companyUpdate: comfig => {
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: ''
    }
  },
  // 投放渠道列表
  getChannelList: config => {
    const body = param2Obj(config.url)
    const startIndex = ((+body.page || 1) - 1) * (+body.rows || 30)
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        list: channel.slice(startIndex, +startIndex + (+body.rows || 30)),
        pageNumber: body.page || 1,
        pageSize: body.rows || 30,
        totalPage: Math.ceil(dailyDetail.length / (body.rows || 30)),
        totalRow: dailyDetail.length
      }
    }
  },
  // 修改充值记录
  charge: config => {
    return {
      retcode: 0,
      msg: '成功',
      status: 200
    }
  },
  // 修改公众号
  tencentEdit: config => {
    return {
      retcode: 0,
      msg: '成功',
      status: 200
    }
  },
  // 部门统计
  department: config => {
    return {
      retcode: 0,
      msg: '成功',
      status: 200,
      data: {
        arr_corp_perf,
        arr_cycle_perf
      }
    }
  }
}
